package com.meixiang.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.util.DensityUtil;

/**
 * 过时价格View
 * author:xiejingwen
 */
public class OldPriceView extends TextView{
    private Paint mPaint;
    private int width;
    private int height;
    private Context mContext;
    private int LineColor=R.color.gray_c8;
    private int LineHeight=1;
    public OldPriceView(Context context) {
        this(context,null);
    }

    public OldPriceView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public OldPriceView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }

    public OldPriceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr);
        mContext=context;
        initView();
    }
    private void initView(){
        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(ContextCompat.getColor(mContext, LineColor));
        mPaint.setStrokeWidth(DensityUtil.dip2px(mContext,LineHeight));
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawLine(0,height/2+DensityUtil.dip2px(mContext,2),width,height/2+DensityUtil.dip2px(mContext,2),mPaint);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        width=getWidth();
        height=getHeight();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setPadding(DensityUtil.dip2px(mContext,4),0,DensityUtil.dip2px(mContext,1),0);
    }
}
